package com.lanxin.oa.zc.service.serviceImpl;

import com.lanxin.bean.ZcAsset;
import com.lanxin.oa.zc.dao.ZcAssetDao;
import com.lanxin.oa.zc.service.ZcAssetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ZcAssetServiceImpl implements ZcAssetService {
    @Autowired
    private ZcAssetDao zcdao;

    @Override
    public List selectzcAsset() {
        return zcdao.selectzcAsset();
    }

    @Override
    public List selectzcTypeIdandName() {
        return zcdao.selectzcTypeIdandName();
    }

    @Override
    public List selectJcbaseByIdandName() {
        return zcdao.selectJcbaseByIdandName();
    }

    @Override
    public List selectJcbaseByDd() {
        return zcdao.selectJcbaseByDd();
    }

    @Override
    public List selectEmpByIdandName() {
        return zcdao.selectEmpByIdandName();
    }

    @Override
    public void insert(ZcAsset zcAsset) {
//        SimpleDateFormat sim =new SimpleDat
        String zcbh=this.createFlowId();
        //资产编码
        zcAsset.setAssetCode(zcbh);
        //创建时间
        zcAsset.setCreateDate(new Date());
        zcdao.add(zcAsset);
    }

    @Override
    public String createFlowId() {
        Integer tadayFlowCount = zcdao.getZcInfoCount();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        StringBuilder taday = new StringBuilder(format.format(new Date()));
        StringBuilder prefix = new StringBuilder("ZC");

        if(tadayFlowCount==0) {
            prefix.append(taday).append("01");
        }else {
            if(tadayFlowCount<10) {
                prefix.append(taday).append("0").append(tadayFlowCount+1);
            }else {
                prefix.append(taday).append(tadayFlowCount+1);
            }
        }

        return prefix.toString();
    }

    @Override
    public ZcAsset selectzcAssetById(Integer oid) {
        return zcdao.selectzcAssetById(oid);
    }

    @Override
    public void updatezcAsset(ZcAsset zcAsset) {
        zcdao.update(zcAsset);

    }

    @Override
    public void baofeizcAsset(Integer oid,String status) {
        ZcAsset zcAsset =zcdao.selectzcAssetById(oid);
        if(status.equals("1")){
            zcAsset.setStatus("1");
        }else {
            zcAsset.setStatus("3");
        }
        System.out.println(zcAsset.toString());
        zcdao.update(zcAsset);
    }

    @Override
    public void deletebaofeizcAset(Integer oid) {
        ZcAsset zcAsset=zcdao.selectzcAssetById(oid);
        zcdao.delete(zcAsset);
    }

    @Override
    public List selecttiaojian(Integer type, String assetCode, String assetNanme) {
        return zcdao.selecttiaojian(type,assetCode,assetNanme);
    }

}
